package com.starview.star.compiler.format;

import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class NumericAttribute extends BaseAttribute<Integer>
{
  private final int count;
  private final Absolute absolute;

  public NumericAttribute(Absolute absolute, int count, int specificity)
  {
    super(true, specificity);
    this.count = count;
    this.absolute = absolute;
  }

  public Absolute isAbsolute()
  {
    return absolute;
  }

  public int count()
  {
    return count;
  }

  @Override
  public Integer apply(Integer original)
  {
    switch (absolute) {
    case absolute:
    default:
      return count;
    case increasing:
      return count + original;
    case decreasing:
      return original - count;
    }
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    switch (absolute) {
    case decreasing:
      disp.append("-");
      break;
    case increasing:
      disp.append("+");
      break;
    case absolute:
      break;
    case mark:
      disp.append("=");
      break;
    }
    disp.append(count);
  }
}
